<%@ page contentType="text/html;charset=UTF-8" %>
<%@ include file="/webpage/include/taglib.jsp"%>
<html style="overflow: auto;">
<head>
	<title>装车确认</title>
	<meta http-equiv="Content-type" content="text/html; charset=utf-8">
	<meta name="decorator" content="ani"/>
	<%@ include file="/webpage/include/bootstraptable.jsp"%>
	<%@include file="/webpage/include/treeview.jsp" %>
	<script type="text/javascript">
	$(document).ready(function() {
		$('#orderTable').bootstrapTable({
		 
		  //请求方法
               method: 'get',
               //类型json
               dataType: "json",
               //显示刷新按钮
               showRefresh: true,
               //显示切换手机试图按钮
               showToggle: true,
               //显示 内容列下拉框
    	       showColumns: true,
    	       //显示到处按钮
    	       showExport: true,
    	       //显示切换分页按钮
    	       showPaginationSwitch: true,
    	       //最低显示2行
    	       minimumCountColumns: 2,
               //是否显示行间隔色
               striped: true,
               //是否使用缓存，默认为true，所以一般情况下需要设置一下这个属性（*）     
               cache: false,    
               //是否显示分页（*）  
               pagination: true,   
                //排序方式 
               sortOrder: "asc",  
               //初始化加载第一页，默认第一页
               pageNumber:1,   
               //每页的记录行数（*）   
               pageSize: 10,  
               //可供选择的每页的行数（*）    
               pageList: [10, 25, 50, 100],
               //这个接口需要处理bootstrap table传递的固定参数,并返回特定格式的json数据  
               url: "${ctx}/sc/logisticsVehicle/findLoadByPage",
               //默认值为 'limit',传给服务端的参数为：limit, offset, search, sort, order Else
               //queryParamsType:'',   
               ////查询参数,每次调用是会带上这个参数，可自定义                         
               queryParams : function(params) {
               	var searchParam = $("#searchForm").serializeJSON();
               	searchParam.pageNo = params.limit === undefined? "1" :params.offset/params.limit+1;
               	searchParam.pageSize = params.limit === undefined? -1 : params.limit;
               	searchParam.orderBy = params.sort === undefined? "" : params.sort+ " "+  params.order;
                   return searchParam;
               },
               //分页方式：client客户端分页，server服务端分页（*）
               sidePagination: "server",
               contextMenuTrigger:"right",//pc端 按右键弹出菜单
               contextMenuTriggerMobile:"press",//手机端 弹出菜单，click：单击， press：长按。
               contextMenu: '#context-menu',
               clickToSelect: true,
               onContextMenuItem: function(row, $el){
                   if($el.data("item") == "edit"){
                   	window.location = "${ctx}/sc/order/order/form?id=" + row.id;
                   } else if($el.data("item") == "delete"){
                        jp.confirm('确认要删除该订单记录吗？', function(){
                       	jp.loading();
                       	jp.get("${ctx}/sc/order/order/delete?id="+row.id, function(data){
                   	  		if(data.success){
                   	  			$('#orderTable').bootstrapTable('refresh');
                   	  			jp.success(data.msg);
                   	  		}else{
                   	  			jp.error(data.msg);
                   	  		}
                   	  	})
                   	   
                   	});
                      
                   } 
               },
              
               onClickRow: function(row, $el){
               },
               columns: [{
		        checkbox: true
		       
		    }
			,{
		        field: 'vehicleType',
		        title: '车辆类型',
		        sortable: true,
		        formatter:function(value, row , index){
		        	return jp.getDictLabel(${fns:toJson(fns:getDictList('sc_logistics_vehicle_type'))}, value, "-");
		        }
		    }
			,{
		        field: 'vehicleAmount',
		        title: '车次',
		        sortable: true
		       
		    }
			,{
		        field: 'customerName',
		        title: '项目',
		        sortable: true
		       
		    },{
		        field: 'stateName',
		        title: '状态',
		        sortable: true
		       
		    }
			,{
		        field: 'deliveryDate',
		        title: '指派日期',
		        sortable: true
		       
		    }					
		     ]	
		});
	});
	
	function getIdSelections() {
	    return $.map($("#orderTable").bootstrapTable('getSelections'), function (row) {
	        return row.id;
	    });
	}
	function finish(){
	    var ids=getIdSelections();
	    if(ids==null || ids==''){
	    	jp.error('请选择需要确认装车的项目!');
	    	return;
	    }
		jp.confirm('确认装车吗，操作后不能恢复！', function(){
			$.ajax({
	            url: "${ctx}/sc/logisticsVehicle/finish",
	            type: "post",
	            dataType:"JSON",
	            data:{ids:ids.toString()},
	            beforeSend: function () {
	                index = layer.load(1, {
	                    shade: [0.5, '#fff'] //0.1透明度的白色背景
	                });
	            },
	            complete: function () {
	                layer.close(index);
	            },
	            success: function (data) {

	                if (data== "1") {
	                    layer.alert('保存成功!', {icon: 1, closeBtn: 0}, function (index) {
	                    	location.reload();
	                    });
	                }
	                else {
	                	layer.alert('保存失败!', {
		                    icon: 2,
		                    title: "提示"
		                });
					}
	            },
	            error: function (e) {
	                layer.alert('保存失败!', {
	                    icon: 2,
	                    title: "提示"
	                });

	            }
	        });
	      	   
		})
	}
</script>
</head>
<body style="width:100%; height:100%; overflow-y: scroll; -webkit-overflow-scrolling: touch;">
<div class="wrap">
	<div class="wrapper wrapper-content">
	<div class="panel panel-primary">
	

	<!-- 工具栏 -->
	 <div id="toolbar">		
		<a id="finish" onclick="finish()" class="btn btn-primary" ><i class="glyphicon glyphicon-plus"></i>确认装车</a>	
	 </div> 

			
		
	<!-- 表格 -->
	<table id="orderTable"   data-toolbar="#toolbar"></table>

    <!-- context menu -->
    <ul id="context-menu" class="dropdown-menu">
    	<shiro:hasPermission name="sc:order:order:edit">
        <li data-item="edit"><a>编辑</a></li>
        </shiro:hasPermission>
        <shiro:hasPermission name="sc:order:order:del">
        <li data-item="delete"><a>删除</a></li>
        </shiro:hasPermission>
        <li data-item="action1"><a>取消</a></li>
    </ul>  
	</div>
	</div>
	</div>
</div>
</body>

</html>